home *** CD-ROM | disk | FTP | other *** search
- Path: inforamp.net!usenet
- From: rmorin@inforamp.net (Randy Charles Morin)
- Newsgroups: comp.lang.c++
- Subject: Re: String operator+ and memory leakage.
- Date: Sun, 21 Apr 1996 07:50:13 GMT
- Organization: InfoRamp Inc., Toronto, Ontario (416) 363-9100
- Message-ID: <4lcerb$4to@sam.inforamp.net>
- References: <4l5fok$feo@utopia.hacktic.nl>
- NNTP-Posting-Host: ts26-10.tor.istar.ca
- X-Newsreader: Forte Free Agent 1.0.82
-
- Mike Tavares <MIKET@cdynamics.com> wrote:
- >The problem is, when new_string is created and returned through a
- >reference, no one ever deletes it.
- >If I change new_string to be an automatic variable I get an error from
- >the compiler about trying to pass a reference to a item that is out of
- >scope.
-
- Is this implementation acceptable...
-
- String
- String::operator+( String& a_string )
- {
- int total_size = string_length + strlen( a_string ) + 1;
- char* temp_array = new char[total_size];
- char* char_array = a_string;
-
- strcpy( temp_array, character_array );
- strcat( temp_array, char_array );
-
- String new_string() = String(temp_array);
- delete [] temp_array;
- return new_string;
- }
-
-
- Agrivar
-
- aka Randy Charles Morin,
- MiddleWorld SoftWare,
- Satisfying Your Bit and Bytes,
- Canada 1-800-363-3780
- Other 1-905-279-2087
- eMail rmorin@inforamp.net
-
-